package cn.edu.xaut.mybatisers.mall.Controller;


import cn.edu.xaut.mybatisers.mall.Entity.Consumer;
import cn.edu.xaut.mybatisers.mall.Exception.ExceptionEntity.LoginException;
import cn.edu.xaut.mybatisers.mall.Exception.ExceptionEntity.ParametersIncompleteException;
import cn.edu.xaut.mybatisers.mall.ServiceImp.LoginServiceImp;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    LoginServiceImp loginServiceImp;

    @ApiOperation("登录")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public Consumer login(Consumer consumer, String verificationCode, HttpServletResponse response, HttpSession session) throws Exception{
        if (consumer.getAccountMember() == null || consumer.getPassword() == null){
            throw new ParametersIncompleteException((consumer.getAccountMember()==null)?"Account Member":"password");
        }
        return  loginServiceImp.Login(consumer, verificationCode, response, session);
    }
}
